package com.clps.excel_CSV_Data;

import org.apache.commons.lang3.StringUtils;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class AbController {

    public static void main(String[] args) throws Exception {
        // 1w 和 10-1w 手机号相同
        phone("140", 20000, "phone1w.csv");
        phone("140", 20000, "10-phone1w.csv");
        // 09-1w 手机号独立
        phone("141", 20000, "09-phone1w.csv");

        int total = 100000;
        whitelist("140", total);
        whitelist("141", total);
        storeuser("140", total);
        storeuser("141", total);
    }

    public static void phone(String pre, int total, String fileName) throws IOException {
        String filePath = "C:\\work\\clps\\project\\boc_mall\\81-extendsStress\\script\\";
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath + fileName))) {
            for (int i = 1; i <= total; i++) {
                writer.write(pre + StringUtils.leftPad(i + "", 8, '0'));
                writer.newLine();
                if (i % 1000 == 0) {
                    writer.flush();
                }
            }
            writer.flush();
        }
    }

    public static void whitelist(String pre, int total) throws IOException {
        String fileName = String.format("000_whitelist_%s.csv", pre);
        String filePath = "C:\\work\\clps\\project\\boc_mall\\81-extendsStress\\script\\";
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath + fileName))) {
            writer.write("id,pull_the_phone_number,whitelist_mobile_phone_numbers,create_time,update_time," +
                    "activity_id,invitation_code,user_name,manager_phone,manager_name,outlet_code,customer_group," +
                    "company_name,remark1,remark2,first_login_time,open_id,is_login");
            writer.newLine();
            for (int i = 1; i <= total; i++) {
                String phone = pre + StringUtils.leftPad(i + "", 8, '0');
                writer.write(String.format("ID_%s,15066668888,%s,2024-04-02 12:00:00,2024-04-02 12:00:00," +
                        "0000018e0d104f7c00163e1ae9870000,3501,%s,15066668888,Hardy,20230222,NULL,NULL,NULL,NULL," +
                        "NULL,NULL,2,", phone, phone, phone));
                writer.newLine();
                if (i % 1000 == 0) {
                    writer.flush();
                }
            }
            writer.flush();
        }
    }

    public static void storeuser(String pre, int total) throws IOException {
        String fileName = String.format("000_storeuser_%s.csv", pre);
        String filePath = "C:\\work\\clps\\project\\boc_mall\\81-extendsStress\\script\\";
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath + fileName))) {
            writer.write("id,phone,name,store_id,amount,create_time,update_time");
            writer.newLine();
            for (int i = 1; i <= total; i++) {
                String phone = pre + StringUtils.leftPad(i + "", 8, '0');
                writer.write(String.format("ID_%s,%s,%s,1518898516582154242,NULL,2024-04-02 12:00:00,2024-04-02 " +
                        "12:00:00", phone, phone, phone));
                writer.newLine();
                if (i % 1000 == 0) {
                    writer.flush();
                }
            }
            writer.flush();
        }
    }

}
